package com.alphaking.Jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.alphaking.bean.Reply;
import com.mysql.jdbc.PreparedStatement;

public class JdbcReply {

	private static Connection con = JdbcUtils.getCon();

	/**
	 * 获得评论的回复
	 * 
	 * @param commentid
	 * @return
	 */
	public static List<Reply> getReplys(int commentid) {

		List<Reply> listReply = new ArrayList<Reply>();

		String sqlSearch = "select * from reply where comment_id = ?";

		try {
			PreparedStatement pstmt = (PreparedStatement) con.prepareStatement(sqlSearch);

			pstmt.setInt(1, commentid);

			ResultSet rst = pstmt.executeQuery();

			while (rst.next()) {

				Reply reply = new Reply();

				reply.setReplyer(rst.getString("replyer"));
				reply.setTouser(rst.getString("touser"));
				reply.setReply_content(rst.getString("content"));

				listReply.add(reply);

			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return listReply;

	}

}
